package org.wangblue;

import org.wangblue.concrete_elements.Book;

import org.wangblue.concrete_elements.Elect;
import org.wangblue.concrete_visitor.InfoVisitor;
import org.wangblue.concrete_visitor.PriceVisitor;
import org.wangblue.object_structure.ObjectStructure;

/**
 * @description: 运行类
 * @author: WangBlue (wangjiping596@gmail.com)
 * @create: 2024-10-02 22:09
 **/
public class Main {
    public static void main(String[] args) {
        // 创建元素对象
        ObjectStructure objectStructure = new ObjectStructure();
        objectStructure.attach(new Book("设计模式", 50));
        objectStructure.attach(new Elect("智能手机", 2000));

        // 创建访问者并让其访问元素
        PriceVisitor priceVisitor = new PriceVisitor();
        InfoVisitor infoVisitor = new InfoVisitor();
        objectStructure.display(priceVisitor);
        objectStructure.display(infoVisitor);


        // 输出总价
        System.out.println("商品总价: " + priceVisitor.getTotalPrice());
    }

}
